﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace WP7BackupService
{
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();

			Loaded += MainWindowLoaded;
			Closed += MainWindowClosed;
		}

		WcfServiceHost _wcfServiceHost; 

		void MainWindowClosed(object sender, EventArgs e)
		{
			_wcfServiceHost.CloseService();
		}

		void MainWindowLoaded(object sender, RoutedEventArgs e)
		{
			try
			{
				_wcfServiceHost = new WcfServiceHost();
				string serviceUri = _wcfServiceHost.CreateService();
				txtServiceUri.Text = serviceUri;
				txtBackupFolder.Text = Settings.BackupFolder;
				
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void TxtTargetFolderTextChanged(object sender, TextChangedEventArgs e)
		{
			Settings.BackupFolder = txtBackupFolder.Text;
		}

		private void AboutClick(object sender, RoutedEventArgs e)
		{
			WPFAboutBox about = new WPFAboutBox(this);
			about.ShowDialog();
		}
	}
}
